goods = [{"name": "电脑", "price": 1999},
         {"name": "鼠标", "price": 10},
         {"name": "游艇", "price": 20},
         {"name": "美女", "price": 998}, ]
lst = []
money = input("请充值：")
shop_sum = 0
if money.isdecimal():
    money = int(money)
    while True:
            for i in range(len(goods)):
                print(i+1,goods[i]['name'],goods[i]['price'])
            num  =  input("输入编号加入购物车，输入n结算，输入q退出")
            if num.isdecimal() and 0<int(num)<=len(goods):
                num = int(num)
                lst.append([goods[num-1]['name'],goods[num-1]['price']])
                print(lst)

            elif num.upper() =="N":
                for i in lst:
                    shop_sum += i[1]
                if shop_sum<=money:
                    print('商品总金额%s剩余金额%s'%(shop_sum,(money-shop_sum)))
                    print("商品列表",lst)
                    break

                elif shop_sum > money:
                    print('你还差%s钱'%(shop_sum-money))
                    money_1 = input("请输入充值金额：")
                    if money_1.isdecimal and money + int(money_1) >= shop_sum:
                        money_1 = int(money_1)
                        print("商品总金额%s剩余金额%s，欢迎下次光临"%(shop_sum,((money + money_1)-shop_sum)))
                        break

                    else:
                        for s in range(len(lst)):
                            for p in range(len(lst)):
                                print(p+1,lst[p])
                            del_shop = input("请输入需要删除的商品编号：")
                            if del_shop.isdecimal() and len(lst)>=int(del_shop)>=1:
                                del_shop = int(del_shop)
                                lst_1 = lst.pop(del_shop-1)
                                shop_sum-=lst_1[1]
                                if shop_sum <= money+int(money_1):
                                    print("商品总金额%s剩余金额%s，欢迎下次光临"%(shop_sum,(int(money_1)+(money-shop_sum))))
                                    print("商品列表", lst)
                                    exit()
                            else:
                                print("请输入正确的商品编号!")

                else:
                    print("输入错误")
            elif num.upper() =="Q":
                print("欢迎下次光临")

                break
            else:
                print("输入错误，请重新输入")
else:
    print("请输入数字")
